<template>
  <customDrawer
    title="pdf预览"
    :autoHide="false" p94Only placement="right" :footer="null"
    @hide="hide"
    @close="hide"
    v-if="isShow"
    ref="customDrawerPdfView">
    <template #content>
      <vueshowpdf
        v-model="isShowPdf"
        ref="pdfviewRef"
        :pdfurl="cpPdfviewSrc"
        class="pdfview-custom"
        :scale="2"
      />
    </template>
  </customDrawer>
</template>

<script>
import vueshowpdf from 'vueshowpdf'


export default {
  desc: 'pdf预览',
  name: 'pdfView',
  components: { vueshowpdf  },
  mounted() {
  },
  data() {
    return {
      isShowPdf: false,
      isShow: false,
      pdfSrc: null,
    }
  },
  methods: {
    show(pdfSrc) {
      this.pdfSrc = pdfSrc
      this.isShow = true
      setTimeout(() => {
        this.$refs.customDrawerPdfView.show()
        this.isShowPdf = true
      }, 500)
    },
    hide() {
      this.isShow = false
      this.isShowPdf = false
      this.$emit('hide')
    },
  },
  watch: {
  },
  computed: {
    // pdf预览地址
    cpPdfviewSrc() {
      let pdfSrc = this.pdfSrc
      if (!pdfSrc) {
        return  null
      }
      //pdfSrc= `${location.origin}/api${pdfSrc}`
      if (pdfSrc.indexOf("?") != -1) {
        pdfSrc += '&tms='+Date.now()
      } else {
        pdfSrc += '?tms='+Date.now()
      }
      pdfSrc += `&X-Token=${sessionStorage.getItem('X-Token')}`
      return pdfSrc
    }
  },
}
</script>

<style lang="scss" >
.pdfview-custom{
  position: relative !important;
  .contor{
    display: none !important;
  }
  .center{
    background: #fff;
    padding: 5px;
  }
}

</style>
